import Cocoa

class AppDelegate: NSObject, NSApplicationDelegate {
    private var statusBarManager: StatusBarManager?
    private var screenshotManager: ScreenshotManager?
    private var hotkeyManager: HotkeyManager?
    
    func applicationDidFinishLaunching(_ notification: Notification) {
        // 初始化状态栏管理器
        statusBarManager = StatusBarManager()
        
        // 初始化截图管理器
        screenshotManager = ScreenshotManager()
        
        // 初始化快捷键管理器
        hotkeyManager = HotkeyManager()
        
        // 设置默认的截图快捷键 (Command + Shift + A)
        hotkeyManager?.registerScreenshotHotkey { [weak self] in
            self?.takeScreenshot()
        }
    }
    
    func applicationWillTerminate(_ notification: Notification) {
        // 清理资源
        hotkeyManager?.unregisterAllHotkeys()
    }
    
    // MARK: - Menu Actions
    
    @objc func takeScreenshot() {
        screenshotManager?.takeScreenshot()
    }
    
    @objc func showSettings() {
        // TODO: 实现设置界面
        let alert = NSAlert()
        alert.messageText = "设置"
        alert.informativeText = "设置功能即将推出..."
        alert.alertStyle = .informational
        alert.addButton(withTitle: "确定")
        alert.runModal()
    }
    
    @objc func quit() {
        // 确保在主线程中执行
        DispatchQueue.main.async {
            NSApplication.shared.terminate(nil)
        }
    }
}
